package net.mingsoft.dashboard.action.web;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import net.mingsoft.base.entity.ResultData;
import net.mingsoft.dashboard.action.q.sharing.SharingCancelQuery;
import net.mingsoft.dashboard.action.q.sharing.SharingCheckPwdQuery;
import net.mingsoft.dashboard.action.q.sharing.SharingListQuery;
import net.mingsoft.dashboard.action.r.FileShareResponse;
import net.mingsoft.document.biz.FileShareBiz;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author gengfa
 * @date 22/01/25
 */
@Api(value = "我的分享", tags = {"工作台-我的分享"})
@Controller("WebSharingAction")
@RequestMapping("/${ms.manager.path}/sharing")
public class MySharingAction {

    @Resource
    FileShareBiz fileShareBiz;

    @ApiOperation(value = "分享列表")
    @PostMapping(value = "/list", consumes = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "success", response = FileShareResponse.class)
    })
    public ResultData list(@RequestBody SharingListQuery query) {
        Page<FileShareResponse> page = fileShareBiz.myShareList(query);
        return ResultData.build().success(page);
    }

    @ApiOperation(value = "收到的分享")
    @PostMapping(value = "/receive", consumes = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "success", response = FileShareResponse.class)
    })
    public ResultData receive(@RequestBody SharingListQuery query) {
        Page<FileShareResponse> page = fileShareBiz.receivedList(query);
        return ResultData.build().success(page);
    }

    @ApiOperation(value = "取消分享")
    @PostMapping(value = "/cancel", consumes = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public ResultData cancel(@RequestBody SharingCancelQuery query) {
        if (fileShareBiz.shareCancel(query)) {
            return ResultData.build().success();
        }
        return ResultData.build().error();
    }

    @ApiOperation(value = "检查密码")
    @PostMapping(value = "/checkpassword", consumes = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public ResultData checkPwd(@RequestBody SharingCheckPwdQuery query) {
        if (fileShareBiz.checkPwd(query)) {
            return ResultData.build().success();
        }
        return ResultData.build().error();
    }
}
